<?php
class Core_Model_Character_Params_List 
	extends Core_Model_Abstract
	implements Iterator
{
	protected $_list	= array();
	
	protected $_listKeys	= array();
	
	protected $_pos		= 0;	
	
	public function addListItem(Core_Model_Character_Param $params)
	{
		if ($this->paramExists($params->getId()))
		{
			throw new Core_Model_Character_Params_Exception('Cannot Add Param: Param Added');
		}
		
		$this->_list[$params->getId()]	= $params;
		$this->_listKeys	= array_keys($this->_list);
	}
	
	public function paramExists($id)
	{
		return array_key_exists($id, $this->_list);	
	}

	public function key()
	{
		debug($this->_findIndex($this->pos));
		return $this->_findIndex($this->pos);
	}
	
	public function current()
	{
		$idx	= $this->_findIndex($this->_pos);
		
		if ($idx === false)
		{
			return false;
		}
		
		return $this->_list[$idx];
	}
	
	public function next()
	{
		++$this->_pos;
	}
	
	public function rewind()
	{
		$this->_pos	= 0;
	}
	
	public function valid()
	{
		return $this->current() === false ? false : true;
	}
	
	protected function _findIndex($index)
	{
		
		$search	= array_key_exists($index, $this->_listKeys);
		if ($search === false)
		{
			return false;
		}
		return $this->_listKeys[$index];
	}
	
	
	public function loadList()
	{
		$mapper	= new Core_Model_Character_Params_Mapper();
		$mapper->fetchAll($this);	
	}
} 